﻿using MD5Hash;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartHotel.BLL;
using SmartHotel.DAL;
using SmartHotel.Model;
using System.Xml.Linq;

namespace SmartHotel.WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MemberController : ControllerBase
    {
        public MemberController(MemberBLL memberBLL)
        {
            MemberBLL = memberBLL;
        }
        
        public MemberBLL MemberBLL { get; }

        /// <summary>
        ///注册接口
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        [HttpPost]
        public int Add(Member member)
        {
            return MemberBLL.Add(member);
        }
        [HttpGet]
        public int Login(string userName, string passWord)
        {
            var user = MemberBLL.GetMemberByName(userName);//找登录的用户
            if (user == null)
            {
                return -1;//用户名不存在
            }
            if (user.Pwd != passWord.GetMD5())
            {
                return -2;//密码错误
            }
            return 1;

        }
        [HttpGet]
        public Member GetMemberByName(string name)
        {
            return MemberBLL.GetMemberByName(name);
        }

        [HttpGet]
        public Member GetMemberById(int id)
        {
            return MemberBLL.GetMemberById(id);
        }
        [HttpPut]
        public int Update(Member member)
        {
            return MemberBLL.Update(member);
        }

        [HttpGet]
        public int SixCode()
        {
            Random rnd = new Random();//随机数类
           return  rnd.Next(100000,999999);

        }
    }
}
